using System;
using Kiwi.Container.DependencyInjection;
using Kiwi.Container.Internal;
using Kiwi.Container.Lifetime;
using Kiwi.Container.Scope;

namespace Kiwi.Container.Registration
{
    public class ComponentRegistrationAs<T> : IComponentRegistration<T>
    {
        public ComponentRegistrationAs(IComponentRegistration inner)
        {
            if (!(typeof (T).IsAssignableFrom(inner.ActualType)))
            {
                Throw.IllegalComponentCast(inner.ActualType, typeof (T));
            }
            Inner = inner;
            inner.ComponentType = new ComponentType(typeof (T));
        }

        public IComponentRegistration Inner { get; set; }

        #region IComponentRegistration<T> Members

        public Type ActualType
        {
            get { return Inner.ActualType; }
        }

        public IComponentType ComponentType
        {
            get { return Inner.ComponentType; }
            set { Inner.ComponentType = value; }
        }

        public IComponentScope ComponentScope
        {
            get { return Inner.ComponentScope; }
            set { Inner.ComponentScope = value; }
        }

        public object Tag
        {
            get { return Inner.Tag; }
            set { Inner.Tag = value; }
        }

        public IEnumerateDependentProperties InjectProperties
        {
            get { return Inner.InjectProperties; }
            set { Inner.InjectProperties = value; }
        }

        public IComponentCacheResolver CacheResolver
        {
            get { return Inner.CacheResolver; }
            set { Inner.CacheResolver = value; }
        }

        public ILifetimeManager LifetimeManager
        {
            get { return Inner.LifetimeManager; }
            set { Inner.LifetimeManager = value; }
        }

        public IComponentActivator Activator
        {
            get { return Inner.Activator; }
        }

        #endregion
    }
}